package com.crm.service.impl.sys.permissionManagement;

import com.crm.dao.mapper.customMapper.permissionManagement.SysCompanyCustomMapper;
import com.crm.dao.mapper.sys.permissionManagement.SysCompanyMapper;
import com.crm.model.entity.sys.permissionManagement.SysCompany;
import com.crm.model.entity.sys.permissionManagement.SysCompanyExample;
import com.crm.service.sys.permissionManagement.SysCompanyDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author yincuimei
 * @Date 2020/12/6 19:24
 */
@Service
public class SysCompanyDbServiceImpl implements SysCompanyDbService {
    @Autowired
    SysCompanyMapper sysCompanyMapper;
    @Autowired
    SysCompanyCustomMapper sysCompanyCustomMapper;

    /**
     * 获取公司列表
     * @return
     */
    @Override
    public List<SysCompany> selectSysCompanyList() {
        SysCompanyExample sysCompanyExample = new SysCompanyExample();
        SysCompanyExample.Criteria criteria = sysCompanyExample.createCriteria();
        criteria.andDeleteStatusEqualTo(Short.parseShort("0"));
        sysCompanyExample.setOrderByClause("province_code asc");
        List<SysCompany> sysCompanyList = sysCompanyMapper.selectByExample(sysCompanyExample);
        return sysCompanyList;
    }

    @Override
    public SysCompany selectSysCompanyById(String CompanyId) {
        SysCompany sysCompany = sysCompanyMapper.selectByPrimaryKey(CompanyId);
        return sysCompany;
    }

    /**
     * 查询所有未删除的公司(管理模块--线程表单所属公司下拉搜索框)
     * @param deleteStatus
     * @return
     */
    @Override
    public List<Map<String, Object>> selectSysCompanyList(Short deleteStatus) {
        return sysCompanyCustomMapper.selectSysCompanyList(deleteStatus);
    }

    /**
     * 查询所有公司+税盘号
     * @return
     */
    @Override
    public List<Map<String, Object>> selectCompanyAndTaxNumberList() {
        return sysCompanyCustomMapper.selectCompanyAndTaxNumberList();
    }

    /**
     * 修改公司信息
     * @param sysCompany
     */
    @Override
    public void updateCompanyTaxNumber(SysCompany sysCompany) {
        sysCompanyMapper.updateByPrimaryKeySelective(sysCompany);
    }

    /**
     * 根据公司查询公司税号
     * @param companyId
     * @return
     */
    @Override
    public String selectCompanyTaxNumber(String companyId) {
        return sysCompanyCustomMapper.selectCompanyTaxNumber(companyId);
    }

    @Override
    public List<SysCompany> selectSysCompanyList(String companyName) {
        SysCompanyExample sysCompanyExample = new SysCompanyExample();
        SysCompanyExample.Criteria criteria = sysCompanyExample.createCriteria();
        criteria.andCompanyNameLike("%" + companyName + "%");
        sysCompanyExample.setOrderByClause("create_tm desc");
        List<SysCompany> sysCompanies =  sysCompanyMapper.selectByExample(sysCompanyExample);
        return sysCompanies;
    }

    @Override
    public Boolean insertCompany(SysCompany sysCompany) {
        int num = sysCompanyMapper.insertSelective(sysCompany);
        return num>0;
    }

    /**
     * 根据名称查询
     * @param companyName
     * @return
     */
    @Override
    public SysCompany selectSysCompanyByName(String companyName) {
        return sysCompanyCustomMapper.selectSysCompanyByName(companyName);
    }

    /**
     * 通过id查询公司
     * @param companyId
     * @return
     */
    @Override
    public List<SysCompany> selectSysCompanyListByCompanyId(String companyId,String compName) {
        return sysCompanyCustomMapper.selectSysCompanyListByCompanyId(companyId,compName);
    }

}
